<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" href="/app/admin/component/layui/css/layui.css" />
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
    </head>
    <body class="pear-container">
        <style>
            .layui-input-block input {
                width: 300px;
            }
        </style>

        <div class="layui-card">
            <div class="layui-card-body">

                <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">祭拜设置</li>
<!--                    <li>鲜花设置</li>-->
<!--                    <li>水果设置</li>-->
                </ul>
                <div class="layui-tab-content">

                    <!-- 基本信息 -->
                    <div class="layui-tab-item layui-show">

                        <form class="layui-form" lay-filter="worshipInfo">

                            <div class="layui-form-item">
                                <label class="layui-form-label">善心充值比例(善心/元)</label>
                                <div class="layui-input-block">
                                    <input type="number" name="kindness_rmb_rate" placeholder="请输入善心充值比例" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">每日免费上香总次数</label>
                                <div class="layui-input-block">
                                    <input type="number" name="filial_piety_count" placeholder="请输入每日免费上香次数" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">每日每个先祖免费上香次数</label>
                                <div class="layui-input-block">
                                    <input type="number" name="each_filial_piety_count" placeholder="请输入每个先祖每日免费上香次数" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">免费上香获取孝心</label>
                                <div class="layui-input-block">
                                    <input type="number" name="filial_piety_amount" placeholder="请输入免费上香可获得孝心额度" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">发布先祖所需黄心</label>
                                <div class="layui-input-block">
                                    <input type="number" name="add_surname_kindness_amount" placeholder="请输入发布先祖所需黄心" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">发布先祖所需孝勋章</label>
                                <div class="layui-input-block">
                                    <input type="number" name="add_surname_amount" placeholder="请输入发布先祖所需孝勋章" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">发布先祖所需功勋章</label>
                                <div class="layui-input-block">
                                    <input type="number" name="add_surname_gd_amount" placeholder="请输入发布先祖所需功勋章" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">发布先祖所需福勋章</label>
                                <div class="layui-input-block">
                                    <input type="number" name="add_surname_fu_amount" placeholder="请输入发布先祖所需福勋章" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="saveWorshipInfo">
                                        提交
                                    </button>
                                </div>
                            </div>
                        </form>

                    </div>

                    <!-- 基本设置 -->
                    <div class="layui-tab-item">

                        <form class="layui-form" lay-filter="flowerInfo">
                            <div class="layui-form-item">
                                <label class="layui-form-label">鲜花图片</label>
                                <div class="layui-input-block">
                                    <img class="img-3" src=""/>
                                    <input type="text" style="display:none" name="flower_img" value="" />
                                    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="image5" permission="app.admin.upload.avatar">
                                        <i class="layui-icon layui-icon-upload"></i>上传图片
                                    </button>
                                    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="attachment-choose-image5" permission="app.admin.upload.attachment">
                                        <i class="layui-icon layui-icon-align-left"></i>选择图片
                                    </button>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">单价(善心)</label>
                                <div class="layui-input-block">
                                    <input type="number" name="flower_price" placeholder="请输入鲜花单价" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="saveFlowerInfo">
                                        提交
                                    </button>
                                </div>
                            </div>
                        </form>

                    </div>

                    <div class="layui-tab-item">

                        <form class="layui-form" lay-filter="fruitInfo">
                            <div class="layui-form-item">
                                <label class="layui-form-label">水果图片</label>
                                <div class="layui-input-block">
                                    <img class="img-3" src=""/>
                                    <input type="text" style="display:none" name="fruit_img" value="" />
                                    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="image6" permission="app.admin.upload.avatar">
                                        <i class="layui-icon layui-icon-upload"></i>上传图片
                                    </button>
                                    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="attachment-choose-image6" permission="app.admin.upload.attachment">
                                        <i class="layui-icon layui-icon-align-left"></i>选择图片
                                    </button>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">单价(善心)</label>
                                <div class="layui-input-block">
                                    <input type="number" name="fruit_price" placeholder="请输入鲜花单价" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="saveFruitInfo">
                                        提交
                                    </button>
                                </div>
                            </div>
                        </form>

                    </div>

                </div>
            </div>

            </div>
        </div>


        <script src="/app/admin/component/layui/layui.js"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        <script>

            // 基础设置
            layui.use(["upload", "layer", "popup"], function() {
                let $ = layui.$;
                let form = layui.form;

                // image
                let input = $("#image").prev();
                input.prev().attr("src", input.val());
                layui.$("#attachment-choose-image").on("click", function() {
                    parent.layer.open({
                        type: 2,
                        title: "选择附件",
                        content: "/app/admin/upload/attachment?ext=jpg,jpeg,png,gif,bmp",
                        area: ["95%", "90%"],
                        success: function (layero, index) {
                            parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                                input.val(data.url).prev().attr("src", data.url);
                            });
                        }
                    });
                });
                layui.upload.render({
                    elem: "#image",
                    url: "/app/admin/upload/image",
                    acceptMime: "image/gif,image/jpeg,image/jpg,image/png",
                    done: function (res) {
                        if (res.code) {
                            return layui.popup.failure(res.msg);
                        }
                        this.item.prev().val(res.data.url).prev().attr("src", res.data.url);
                    }
                });

                // image2
                let input2 = $("#image2").prev();
                input2.prev().attr("src", input2.val());
                layui.$("#attachment-choose-image2").on("click", function() {
                    parent.layer.open({
                        type: 2,
                        title: "选择附件",
                        content: "/app/admin/upload/attachment?ext=jpg,jpeg,png,gif,bmp",
                        area: ["95%", "90%"],
                        success: function (layero, index) {
                            parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                                input2.val(data.url).prev().attr("src", data.url);
                            });
                        }
                    });
                });
                layui.upload.render({
                    elem: "#image2",
                    url: "/app/admin/upload/image",
                    acceptMime: "image/gif,image/jpeg,image/jpg,image/png",
                    done: function (res) {
                        if (res.code) {
                            return layui.popup.failure(res.msg);
                        }
                        this.item.prev().val(res.data.url).prev().attr("src", res.data.url);
                    }
                });

                // image3
                let input3 = $("#image3").prev();
                input3.prev().attr("src", input3.val());
                layui.$("#attachment-choose-image3").on("click", function() {
                    parent.layer.open({
                        type: 2,
                        title: "选择附件",
                        content: "/app/admin/upload/attachment?ext=jpg,jpeg,png,gif,bmp",
                        area: ["95%", "90%"],
                        success: function (layero, index) {
                            parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                                input3.val(data.url).prev().attr("src", data.url);
                            });
                        }
                    });
                });
                layui.upload.render({
                    elem: "#image3",
                    url: "/app/admin/upload/image",
                    acceptMime: "image/gif,image/jpeg,image/jpg,image/png",
                    done: function (res) {
                        if (res.code) {
                            return layui.popup.failure(res.msg);
                        }
                        this.item.prev().val(res.data.url).prev().attr("src", res.data.url);
                    }
                });

                // image4
                let input4 = $("#image4").prev();
                input4.prev().attr("src", input4.val());
                layui.$("#attachment-choose-image3").on("click", function() {
                    parent.layer.open({
                        type: 2,
                        title: "选择附件",
                        content: "/app/admin/upload/attachment?ext=jpg,jpeg,png,gif,bmp",
                        area: ["95%", "90%"],
                        success: function (layero, index) {
                            parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                                input4.val(data.url).prev().attr("src", data.url);
                            });
                        }
                    });
                });
                layui.upload.render({
                    elem: "#image4",
                    url: "/app/admin/upload/image",
                    acceptMime: "image/gif,image/jpeg,image/jpg,image/png",
                    done: function (res) {
                        if (res.code) {
                            return layui.popup.failure(res.msg);
                        }
                        this.item.prev().val(res.data.url).prev().attr("src", res.data.url);
                    }
                });

                // image5
                let input5 = $("#image5").prev();
                input5.prev().attr("src", input5.val());
                layui.$("#attachment-choose-image3").on("click", function() {
                    parent.layer.open({
                        type: 2,
                        title: "选择附件",
                        content: "/app/admin/upload/attachment?ext=jpg,jpeg,png,gif,bmp",
                        area: ["95%", "90%"],
                        success: function (layero, index) {
                            parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                                input5.val(data.url).prev().attr("src", data.url);
                            });
                        }
                    });
                });
                layui.upload.render({
                    elem: "#image5",
                    url: "/app/admin/upload/image",
                    acceptMime: "image/gif,image/jpeg,image/jpg,image/png",
                    done: function (res) {
                        if (res.code) {
                            return layui.popup.failure(res.msg);
                        }
                        this.item.prev().val(res.data.url).prev().attr("src", res.data.url);
                    }
                });

                // image6
                let input6 = $("#image6").prev();
                input6.prev().attr("src", input6.val());
                layui.$("#attachment-choose-image3").on("click", function() {
                    parent.layer.open({
                        type: 2,
                        title: "选择附件",
                        content: "/app/admin/upload/attachment?ext=jpg,jpeg,png,gif,bmp",
                        area: ["95%", "90%"],
                        success: function (layero, index) {
                            parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                                input6.val(data.url).prev().attr("src", data.url);
                            });
                        }
                    });
                });
                layui.upload.render({
                    elem: "#image6",
                    url: "/app/admin/upload/image",
                    acceptMime: "image/gif,image/jpeg,image/jpg,image/png",
                    done: function (res) {
                        if (res.code) {
                            return layui.popup.failure(res.msg);
                        }
                        this.item.prev().val(res.data.url).prev().attr("src", res.data.url);
                    }
                });

                // 提交
                form.on("submit(saveWorshipInfo)", function(data){
                    $.ajax({
                        url: "/app/admin/config/update",
                        dataType: "json",
                        type: "POST",
                        data: {worship: data.field},
                        success: function (res) {
                            if (res.code) {
                                return layui.popup.failure(res.msg);
                            }
                            return layui.popup.success("操作成功");
                        }
                    });
                    return false;
                });
            });

            // 菜单设置
            layui.use(["upload", "layer", "popup"], function() {
                let $ = layui.$;
                let form = layui.form;
                // 提交
                form.on("submit(saveFlowerInfo)", function(data){
                    $.ajax({
                        url: "/app/admin/config/update",
                        dataType: "json",
                        type: "POST",
                        data: {flower: data.field},
                        success: function (res) {
                            if (res.code) {
                                return layui.popup.failure(res.msg);
                            }
                            return layui.popup.success("操作成功");
                        }
                    });
                    return false;
                });
            });

            layui.use(["upload", "layer", "popup"], function() {
                let $ = layui.$;
                let form = layui.form;
                // 提交
                form.on("submit(saveFruitInfo)", function(data){
                    $.ajax({
                        url: "/app/admin/config/update",
                        dataType: "json",
                        type: "POST",
                        data: {fruit: data.field},
                        success: function (res) {
                            if (res.code) {
                                return layui.popup.failure(res.msg);
                            }
                            return layui.popup.success("操作成功");
                        }
                    });
                    return false;
                });
            });



            layui.use(["form"], function () {
                let form = layui.form;
                let $ = layui.$;
                $.ajax({
                    url: "/app/admin/config/get",
                    dataType: "json",
                    success: function (res) {
                        if (res.code) {
                            return layui.popup.failure(res.msg);
                        }
                        $("#image5").prev().val(res.flower.flower_img).prev().attr("src", res.flower.flower_img);
                        form.val('flowerInfo', res.flower);
                        $("#image6").prev().val(res.fruit.fruit_img).prev().attr("src", res.fruit.fruit_img);
                        form.val('fruitInfo', res.fruit);
                        $("#image").prev().val(res.worship.worship_bg).prev().attr("src", res.worship.worship_bg);
                        $("#image2").prev().val(res.worship.worship_entry_one).prev().attr("src", res.worship.worship_entry_one);
                        $("#image3").prev().val(res.worship.worship_entry_two).prev().attr("src", res.worship.worship_entry_two);
                        $("#image4").prev().val(res.worship.worship_entry_three).prev().attr("src", res.worship.worship_entry_three);
                        form.val("worshipInfo", res.worship);
                    }
                });

            });

        </script>

    </body>
</html>
